﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Public;

namespace DAL
{
    public class UnitDAL
    {
        DBConnection conn = new DBConnection();
        public DataSet GetAllUnitCBX()
        {
            return conn.LoadDBComBox("SELECT * FROM Unit");
        }
        public DataTable searchProUnit(string searchValue)
        {
            return conn.loadData("SELECT * FROM Unit WHERE unitId LIKE '%" + searchValue + "%'");
        }

        public int AddProductUnit(Unit unit)
        {
            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@unitName"; value[0] = unit.UnitName;
            return conn.Update("INSERT INTO Unit(unitName) VALUES (@unitName)",
                                    name, value, Nparameter);
        }
        public int UpdateProductUnit(Unit unit)
        {
            int Nparameter = 2;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@unitName"; value[0] = unit.UnitName;
            name[1] = "@unitId"; value[1] = unit.UnitId;
            return conn.Update("UPDATE Unit SET unitName=@unitName WHERE unitId=@unitId",
                                    name, value, Nparameter);
        }
    }
}
